package com.lsy.weizhi2.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lsy.weizhi2.R;
import com.lsy.weizhi2.config.Constants;

/**
 * Created by 嗨哟 on 2017/3/10.
 */
public class ActivityItem extends LinearLayout {
    private Context context;
    private LinearLayout activity_item;
    private ImageView activity_item_iv;
    private TextView activity_item_title,activity_item_content;
    private int background;
    public ActivityItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        LayoutInflater.from(context).inflate(R.layout.activity_item,this,true);
        TypedArray typedArray=context.obtainStyledAttributes(attrs, R.styleable.ActivityItem);
        background=typedArray.getResourceId(R.styleable.ActivityItem_Back,0);
        typedArray.recycle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        activity_item= (LinearLayout) findViewById(R.id.activity_item);
        activity_item_iv= (ImageView) findViewById(R.id.activity_item_iv);
        activity_item_title= (TextView) findViewById(R.id.activity_item_title);
        activity_item_content= (TextView) findViewById(R.id.activity_item_content);
        if(background!=0){
            activity_item.setBackgroundResource(background);
        }
    }

    public void setTitle(String title){
        activity_item_title.setText(title);
    }

    public void setContent(String content){
        activity_item_content.setText(content);
    }

    public void setImage(String image){
        Glide.with(context)
                .load(Constants.SERVICE_IP+image)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(activity_item_iv);
    }

    public void setImage(int image){
        activity_item_iv.setImageResource(image);
    }
}
